using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Microsoft.Practices.PageFlow.Utils;
using System.Globalization;

namespace WCSFContrib.PageFlow.Xml.Configuration
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
    public class ViewConfigurationElementCollection : ConfigurationElementCollection
    {
        public ViewConfigurationElementCollection()
        {
        }

        protected override bool ThrowOnDuplicate
        {
            get { return true; }
        }

        public void Add(ViewConfigurationElement view)
        {
            BaseAdd(view);
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
        public bool Contains(string viewName)
        {
            Guard.ArgumentNotNullOrEmptyString(viewName, "viewName");
            return base.BaseGet(viewName.ToLower(CultureInfo.CurrentCulture)) != null;
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMap; }
        }

        protected override string ElementName
        {
            get { return "view"; }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new ViewConfigurationElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ViewConfigurationElement)element).Name.ToLower(CultureInfo.CurrentCulture);
        }

        public ViewConfigurationElement this[int index]
        {
            get { return (ViewConfigurationElement)base.BaseGet(index); }
        }

        public new ViewConfigurationElement this[string viewName]
        {
            get
            {
                Guard.ArgumentNotNullOrEmptyString(viewName, "viewName");
                return (ViewConfigurationElement)base.BaseGet(viewName.ToLower(CultureInfo.CurrentCulture));
            }
        }
    }
}
